<?php
declare (strict_types = 1);

namespace app\admin\controller;

use think\App;
use app\common\builder\TableBuilder;
use app\common\builder\TableFront;
use think\response\Json;

class District extends Base
{

    //主键
    protected $pk = 'id';

    //主模型
    protected $model = '\app\common\model\District';

    public function index()
    {
        return $this->setTable();
    }

    //自动构建table,按需修改
    public function setTable()
    {
        $tableFront = TableFront::getInstance()
            ->addRow(['type' => 'checkbox', 'fixed' => 'left', 'field' => '', 'title' => '全选'])
            ->addRow(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addRow(['field' => 'title', 'title' => '标题', 'modify' => 'add|edit', 'format' => 'input'])
            ->addRow(['field' => 'check_title', 'title' => '检查报告标题', 'modify' => 'add|edit', 'format' => 'input','required'=>false])
            ->addRow(['field' => 'check_desc', 'title' => '检查报告描述', 'modify' => 'add|edit', 'format' => 'input','required'=>false])
            ->addRow(['field' => 'check_yh', 'title' => '检查报告隐患', 'modify' => 'add|edit', 'format' => 'input','required'=>false])
            ->addRow(['field' => 'check_zg', 'title' => '检查报告整改', 'modify' => 'add|edit', 'format' => 'input','required'=>false])
            ->addRow(['field' => 'sort', 'title' => '排序', 'width' => 120, 'modify' => 'add|edit', 'format' => 'input',
                // 'templet' => '<div>
                // <input type="text" data-key="sort" data-id="{{d.id}}" data-url="' . url('update') . '" value="{{d.sort}}" class="layui-input x-sort tableInput"/>
                // </div>'
            ])
            ->addRow(['field' => 'create_time', 'title' => '创建时间'])
            ->addRow(['field' => 'update_time', 'title' => '更新时间'])
            ->addRow(['fixed' => 'right', 'align' => 'center', 'toolbar' => '#barDemo', 'title' => '操作', 'width' => 300]);

        return TableBuilder::getInstance()
            ->addColumns($tableFront)
            ->addRightButtons(['edit' => ['width' => 1000, 'height' => 1000],
            'showpro' => [
                'type' => 'edit',
                'title' => '查看区域场所',
                'width' => 1400,
                'height' => 1200,
                'url' => url('districtPro/index', ['name' => request()->controller() . '_' . request()->action()])->build(),
            ], 'delete'])
            ->addTopButtons(['add', 'deleteAll'])
            ->setSearch($this->setSearch())
            ->fetch();
    }
    //自动构建Search，按需修改
    public function setSearch()
    {
        return TableFront::getInstance()
            ->setSearch(['title', '名称', 'input', '', '', '', 'like']);
    }
    

    public function save($param = [], $model = true): Json
    {
        return parent::save($param, $model); // TODO: Change the autogenerated stub
    }

}
